@extends('layout')
@section('title', 'showPage')
@section('style')
    @parent
    <style>
        .alert{
            color: green;
        }
    </style>
@endsection
@section('script')
    @parent
    <script>
        //For all the post method
        !(function ($) {
            $('#submit').click(function () {
                var age = $('#age').val();
                var name = $('#name').val();
                $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    }
                });
                $.ajax({
                    type: "post",
                    url: "checkAge",
                    data: {'name':name,"age":age},
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    success: function(data){
                        console.log(datas);
                    },
                    error:function (data) {
                        console.log(data.responseJSON.errors);
                    }
                })
            });
        })(jQuery)
    </script>
@endsection

@section('links')
    @parent
    <p><a href="{{url('student')}}">url()</a></p>
    <p><a href="{{action('FoodController@test1')}}">action()</a></p>
    <p><a href="{{route('student')}}">route()</a></p>
@endsection
@section('content')
    {{--@component('componet.alert')
        @slot('title')
            Forbidden
        @endslot
        你没有权限访问这个资源！
        <strong>Whoops!</strong> Something went wrong!
    @endcomponent--}}
    <meta name="csrf-token" content="{{csrf_token()}}">
    <p>{{$name}}</p>
    <p>{{$names[1]}}</p>
    <p>{{var_dump($names)}}</p>
    <p>{{time()}}</p>
    <p>{{in_array($name,$names)?'true':'false'}}</p>
    <p>{{isset($name)?$name:'default'}}=={{$name or 'default'}}</p>
    <p>
        @if(!empty($name))
            i`m {{$name}}
        @else
            i`m nothing
        @endif
    </p>
    <p>
        @for($i=0;$i<10;$i++)
            {{$i}}
        @endfor
    </p>
    <p>
        @forelse($names as $name)
            {{$name}}
        @empty
            null
        @endforelse
    </p>
    <p>
        {{$list['name']}}
    </p>
    @if (session('err'))
        <div>
            {{ session('err') }}
        </div>
    @endif
    {{--<form action="checkAge" method="post">
        {{csrf_field()}}
        <input type="number" name="age">
        <input type="text" name="name">
        <input type="submit">
    </form>--}}
    <input id="name" type="text" name="name">
    <input id="age" type="number" name="age">
    <input type="submit" id="submit">
    @if (count($errors) > 0)
        <div class="alert alert-danger">
            <ul>
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif
{{--@includeWhen(1==1, 'welcome', ['some' => 'data'])--}}
@endsection